package neusoft.yuejian_11.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.List;

import neusoft.yuejian_11.adapter.PostListAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.PostBean;
import neusoft.yuejian_11.fragment.SpaceItemDecoration;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.PostModel;
import neusoft.yuejian_11.R;

//俱乐部里的晒图列表(已改）
public class ClubPostActivity extends BaseActivity implements RetrofitListener {
    private RecyclerView recyclerView;
    private PostListAdapter adapter;
    private int clubId;
    private  String clubname;
    private TextView titleView;
    private ImageButton imageButtonBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club_post);
        initView();
        initData();

        //返回前一页
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void initData() {
        clubId = getIntent().getIntExtra("c_id",-1);
        clubname =getIntent().getStringExtra("c_name");
        titleView.setText(clubname);
        PostModel postModel=new PostModel();
        postModel.getCPost(String.valueOf(clubId),this);
    }

    private void initView() {
        titleView = (TextView) findViewById(R.id.textView_club_name);
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        List<PostBean> p=(List<PostBean>)o;
        adapter = new PostListAdapter(ClubPostActivity.this,p);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(ClubPostActivity.this, 2);
        gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new SpaceItemDecoration(8));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }
}
